package com.sunlands.zlcx.usercenter.domain.log;

import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.UpdateTimestamp;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.io.Serializable;
import java.util.Date;
/**
 * @author anjl
 * @date 6:16 PM 2019/7/11
 * description: 记录用户登录日志
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity(name = "tz_user_login_log")
@DynamicUpdate
@DynamicInsert
public class LoginLogDO implements Serializable {
    private static final long serialVersionUID = 7591165953973058441L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private Long userId;
    /**
     * 用户名称（昵称）
     */
    private String userName;
    /**
     * @see LoginLogDO.LoginTypeEnum
     */
    private Integer loginType;
    private String ip;
    /**
     * 创建时间
     */
    @CreationTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;
    /**
     * 修改时间
     */
    @UpdateTimestamp
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @SuppressWarnings("all")
    public enum LoginTypeEnum{
        MP_LOGIN(1,"MP_LOGIN"),
        PHONE_LOGIN(2,"MP_LOGIN"),
        NORMAL_LOGIN(3,"MP_LOGIN");

        public final Integer type;
        public final String desc;

        private LoginTypeEnum(Integer type, String desc){
            this.desc = desc;
            this.type = type;
        }
    }
}
